package tests;

import io.TimeTablesReader;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import entities.ClassRoom;
import entities.Course;
import entities.TimeTableColumn;
import manager.Manager;

public class JUnitTest {

	protected class TimeTablesReaderTester extends TimeTablesReader {
		@Override
		public void readFile() {
			ArrayList<Course> test = new ArrayList<Course>();
			test.add(new Course("CS3201", 3, 200, "mark"));
			ArrayList<Course> timeTableEntries = null;

			try {
				timeTableEntries = this.getTimeTableEntries();

			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			Assert.assertEquals(test, timeTableEntries);
		}
	}

	/*
	 * check IO to see the input is it correct
	 */
	@Test
	public void checkIO() {
		(new TimeTablesReaderTester()).readFile();
		Assert.assertTrue(true);
	}

	/*
	 * check the calculatePrecentage function test the percentage correct or not
	 * when the capacity is 50
	 */
	@Test
	public void test1() throws FileNotFoundException, IOException {
		boolean result;
		Course yyy = new Course("CS3201", 3, 1, "mark");
		result = (new Manager()).calculatePrecentage(yyy);
		Assert.assertEquals(result, false);
	}

	/*
	 * check the calculatePrecentage function test the percentage correct or not
	 * when the capacity is 50
	 */
	@Test
	public void test50() throws FileNotFoundException, IOException {
		boolean result;
		Course yyy = new Course("CS3201", 3, 50, "mark");
		result = (new Manager()).calculatePrecentage(yyy);
		Assert.assertEquals(result, false);
	}

	/*
	 * check the calculatePrecentage function test the percentage correct or not
	 * when the capacity is 200
	 */
	@Test
	public void test100() throws FileNotFoundException, IOException {
		boolean result;
		Course yyy = new Course("CS3201", 3, 200, "mark");
		result = (new Manager()).calculatePrecentage(yyy);
		Assert.assertEquals(result, true);
	}

	/*
	 * check the calculatePrecentage function test the percentage correct or not
	 * when the capacity is 300
	 */
	@Test
	public void test300() throws FileNotFoundException, IOException {
		boolean result;
		Course yyy = new Course("CS3201", 3, 300, "mark");
		result = (new Manager()).calculatePrecentage(yyy);
		Assert.assertEquals(result, true);
	}

	/*
	 * check the calculatePrecentage function test the percentage correct or not
	 * when the capacity is 400
	 */
	@Test
	public void test400() throws FileNotFoundException, IOException {
		boolean result;
		Course yyy = new Course("CS3201", 3, 400, "mark");
		result = (new Manager()).calculatePrecentage(yyy);
		Assert.assertEquals(result, false);
	}

	/*
	 * check the isAvailable function in TimetableColumn() when there is a
	 * course in the timetable
	 */
	@Test
	public void testIsAvilable_course() {
		boolean result;
		TimeTableColumn col;
		Course c = new Course("CS3201", 3, 400, "mark");
		col = new TimeTableColumn(c);
		result = col.isAvailable();
		Assert.assertEquals(result, false);
	}

	/*
	 * check the isAvailable function in TimetableColumn() when there is no
	 * course in the timetable
	 */
	@Test
	public void testIsAvilable_null() {
		boolean result;
		TimeTableColumn col;
		Course c = null;
		col = new TimeTableColumn(c);
		result = col.isAvailable();
		Assert.assertEquals(result, true);
	}

	/*
	 * check the toString function in TimetableColumn()
	 */
	@Test
	public void testToString_TimeTableColumn() {
		String s;
		TimeTableColumn col;
		Course c = new Course("CS3201", 3, 400, "mark");
		col = new TimeTableColumn(c);
		boolean result = col.isAvailable();
		s = col.toString();
		Assert.assertEquals(s,
				"Course: CS3201	Room: null	ERROR	Duration : 3	ERROR - ERROR	mark");
	}

	/*
	 * test the checknull function in Manager()
	 */
	@Test
	public void testChecknull() throws FileNotFoundException, IOException {
		boolean result;
		ClassRoom res;
		Course courseTable;
		res = new ClassRoom("4412", "AC2", 200, "Red");
		courseTable = new Course("CS3343", 3, 180, "Mary Wong");
		result = (new Manager()).checknull(res, courseTable);
		Assert.assertEquals(result, true);
	}

	/*
	 * test toString function in Course()
	 */
	@Test
	public void toString_Course() {
		String s;
		Course c = new Course("CS3201", 3, 300, "mark");
		s = c.toString();
		// Assert.assertEquals(s, "Course: " + "CS3201" + "	Room: " + "1234" +
		// "	" + "false" + "	" + "0900 - 1000" + "	" + "mark");
		Assert.assertEquals(s, "Course: CS3201	Room: null	ERROR	Duration : 3	ERROR - ERROR	mark");
	}

	// Test checkTime() in Course()
	@Test
	public void test_checkTime1() {
		Course A = new Course();
		String result = A.checkStartTime(1) + A.checkEndTime(1);
		Assert.assertEquals(result, "0900 - 1000");
	}

	// Test checkTime() in Course()
	@Test
	public void test_checkTime2() {
		Course A = new Course();
		String result = A.checkStartTime(2) + A.checkEndTime(2);
		Assert.assertEquals(result, "1000 - 1100");
	}

	// Test checkTime() in Course()
	@Test
	public void test_checkTime3() {
		Course A = new Course();
		String result = A.checkStartTime(3) + A.checkEndTime(3);
		Assert.assertEquals(result, "1100 - 1200");
	}

	// Test checkTime() in Course()
	@Test
	public void test_checkTime4() {
		Course A = new Course();
		String result = A.checkStartTime(4) + A.checkEndTime(4);
		Assert.assertEquals(result, "1200 - 1300");
	}

	// Test checkTime() in Course()
	@Test
	public void test_checkTime5() {
		Course A = new Course();
		String result = A.checkStartTime(5) + A.checkEndTime(5);
		Assert.assertEquals(result, "1300 - 1400");
	}

	// Test checkTime() in Course()
	@Test
	public void test_checkTime6() {
		Course A = new Course();
		String result = A.checkStartTime(6) + A.checkEndTime(6);
		Assert.assertEquals(result, "1400 - 1500");
	}

	// Test checkTime() in Course()
	@Test
	public void test_checkTime7() {
		Course A = new Course();
		String result = A.checkStartTime(7) + A.checkEndTime(7);
		Assert.assertEquals(result, "1500 - 1600");
	}

	// Test checkTime() in Course()
	@Test
	public void test_checkTime8() {
		Course A = new Course();
		String result = A.checkStartTime(8) + A.checkEndTime(8);
		Assert.assertEquals(result, "1600 - 1700");
	}

	// Test checkTime() in Course()
	@Test
	public void test_checkTime9() {
		Course A = new Course();
		String result = A.checkStartTime(9) + A.checkEndTime(9);
		Assert.assertEquals(result, "1700 - 1800");
	}

	// Test checkTime() in Course()
	@Test
	public void test_checkTime10() {
		Course A = new Course();
		String result = A.checkStartTime(10) + A.checkEndTime(10);
		Assert.assertEquals(result, "1800 - 1900");
	}

	// Test checkTime() in Course()
	@Test
	public void test_checkTime11() {
		Course A = new Course();
		String result = A.checkStartTime(11) + A.checkEndTime(11);
		Assert.assertEquals(result, "1900 - 2000");
	}

	// Test checkTime() in Course()
	@Test
	public void test_checkTime12() {
		Course A = new Course();
		String result = A.checkStartTime(0) + A.checkEndTime(0);
		Assert.assertEquals(result, "ERROR - ERROR");
	}

	// Test test_checkTime in Course()
	@Test
	public void test_hashCode() {
		Course A = new Course();
		int result = A.hashCode();
		Assert.assertEquals(result, result);
	}

	// Test equal() in Course()
	@Test
	public void test_equal1() {
		Course j = new Course("CS3201", 3, 300, "mark");
		Course c = new Course("CS3201", 3, 300, "mark");
		boolean result = c.equals(j);
		Assert.assertEquals(result, true);
	}

	// Test equal() in Course()
	@Test
	public void test_equal2() {
		Course j = new Course("CS3201", 3, 300, "joe");
		Course c = new Course("CS3201", 3, 300, "mark");
		boolean result = c.equals(j);
		Assert.assertEquals(result, false);
	}

	// Test equal() in Course()
	@Test
	public void test_equal3() {
		Course j = new Course("CS3201", 3, 719, "mark");
		Course c = new Course("CS3201", 3, 300, "mark");
		boolean result = c.equals(j);
		Assert.assertEquals(result, false);
	}

	// Test equal() in Course()
	@Test
	public void test_equal4() {
		Course j = new Course("CS3201", 2, 300, "mark");
		Course c = new Course("CS3201", 3, 300, "mark");
		boolean result = c.equals(j);
		Assert.assertEquals(result, false);
	}

	// Test equal() in Course()
	@Test
	public void test_equal5() {
		Course j = new Course("GE2227", 3, 300, "mark");
		Course c = new Course("CS3201", 3, 300, "mark");
		boolean result = c.equals(j);
		Assert.assertEquals(result, false);
	}

	// Test equal() in Course()
	@Test
	public void test_equal6() {
		Course j = new Course("CS3201", 3, 300, "joe");
		ClassRoom m = new ClassRoom("4412", "AC2", 200, "Red");
		boolean result = j.equals(m);
		Assert.assertEquals(result, false);
	}

	// not finished
	@Test
	public void test_checkLecturer() throws FileNotFoundException, IOException {
		ClassRoom a = new ClassRoom("4412", "AC2", 300, "Red");
		/*
		 * Course b = new Course("CS3201", "11", 300, "bernard"); Course j = new
		 * Course("CS3202", "11", 300, "joe"); Course m = new Course("CS3203",
		 * "11", 300, "mark"); Course r = new Course("CS3204", "11", 300,
		 * "bear"); Course h = new Course("CS3205", "11", 300, "hung");
		 */
		Course g = new Course("CS3206", 11, 300, "hello");
		Manager t = new Manager();
		boolean result = t.checkLecturer(a, g);
		t.printTable();
		// Assert.assertEquals(result, true);
	}

	@Test
	public void test_printTable() throws FileNotFoundException, IOException {
		Manager t = new Manager();
		t.printTable();
	}

	// not finished
	@Test
	public void test_write() throws FileNotFoundException, IOException {
		Course b = new Course();
		b.set_assigned_crm("4412");
		// System.out.print(b.assigned_crm);
		// System.out.print(test);
		Manager f = new Manager();
		f.write(b);

	}

	@Test
	public void test_Vaildate() throws FileNotFoundException, IOException {
		Manager m = new Manager();
		ArrayList<Course> c = new ArrayList<Course>();
		m.validate(c);
	}

	@Test
	public void test_checkWeek1() {
		Course A = new Course();
		String result = A.checkWeek(1);
		Assert.assertEquals(result, "Mon");
	}

	@Test
	public void test_checkWeek2() {
		Course A = new Course();
		String result = A.checkWeek(2);
		Assert.assertEquals(result, "Tue");
	}

	@Test
	public void test_checkWeek3() {
		Course A = new Course();
		String result = A.checkWeek(3);
		Assert.assertEquals(result, "Wed");
	}

	@Test
	public void test_checkWeek4() {
		Course A = new Course();
		String result = A.checkWeek(4);
		Assert.assertEquals(result, "Thu");
	}

	@Test
	public void test_checkWeek5() {
		Course A = new Course();
		String result = A.checkWeek(5);
		Assert.assertEquals(result, "Fri");
	}

	@Test
	public void test_checkWeek6() {
		Course A = new Course();
		String result = A.checkWeek(0);
		Assert.assertEquals(result, "ERROR");
	}

	@Test
	public void test_setClass() {
		Course c = new Course();
		TimeTableColumn a = new TimeTableColumn();
		a.setClass(c);
	}

	@Test
	public void test_getCourse() {
		TimeTableColumn a = new TimeTableColumn();
		a.getCourse();
	}

	// not finished
	/*@Test
	
	public void test_getInstructor() {
		TimeTableColumn a = new TimeTableColumn();
		// String test1=a.test;

		System.out.print(a);
		// a.getInstructor();
	}
*/
	@Test
	public void testsetClass() {
		TimeTableColumn timeTableColumn = new TimeTableColumn();
		Course course = new Course();
		timeTableColumn.setClass(course);
	}

	@Test
	public void testgetCourse() {
		TimeTableColumn timeTableColumn = new TimeTableColumn();
		Course course = new Course();
		course = timeTableColumn.getCourse();
		// Assert.assertEquals(course, course);
	}

	@Test
	public void testgetInstructor() {
		Course course;
		course = new Course("CS3343", 3, 180, "Mary Wong");
		TimeTableColumn timeTableColumn = new TimeTableColumn(course);
		String instructor = timeTableColumn.getInstructor();
		Assert.assertEquals(instructor, "Mary Wong");
	}
}